using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using System.Web.Security;
using DomesticBank.Models;


namespace DomesticBank.Controllers {
	[HandleError]
	public class HomeController : Controller {
		public ActionResult Index() {
			ViewData ["Message"] = "Welcome to ASP.NET MVC on Mono!";
			return View();
		}
		
		
		public ActionResult Login(string email, string pass) {
			UsersData data = new UsersData();
			User user = data.getUser(email, pass);
			
			if(user != null) {
				FormsAuthentication.SetAuthCookie("auth_security", true);
				Session["user"] = user;
				
				return Redirect("/Accounts");
			} else {
				return RedirectToAction("Index");
			}
		}
		
		
		public ActionResult Logout() {
			Session.Abandon();
			FormsAuthentication.SignOut();
			
			return RedirectToAction("Index");
		}
	}
}